package org.jadapter.tests;

import junit.framework.TestCase;

import org.jadapter.tests.examples.simple.adapters.BSize;
import org.jadapter.tests.examples.simple.adapters.IA2IB;
import org.jadapter.tests.examples.simple.adapters.IB2IC;
import org.jadapter.tests.examples.simple.adapters.ICSize;
import org.jadapter.tests.examples.simple.api.IA;
import org.jadapter.tests.examples.simple.api.Size;
import org.jadapter.tests.examples.simple.impl.A;

public class SimpleCase extends TestCase {
	// todo rename to TestExmpleTestCode :)
      
    // just to ensure that the test input code works
    public void testTheTest() {       
        IA a = new A();
               
        a.setA("a");
        
        // we can adapt A -> B
        IA2IB ab = new IA2IB(a);
        ab.setB("b");

        // and B -> C
        IB2IC abc = new IB2IC(ab);
        abc.setC("c");
        
        // we have C -> Size
        final Size cSize = new ICSize(abc);
        assertEquals(1, cSize.size());
        
        // what about the a and b in that component?
        final Size abSize = new BSize(abc);
        assertEquals(2, abSize.size());
        
        Size abcSize = new Size(){
            public int size() {
                return abSize.size() + cSize.size();
            }       
        };
        
        assertEquals(3, abcSize.size());
        a.setA("aaa");
        ab.setB("bb");
        assertEquals(5, abSize.size());
        abc.setC("cccc");
        assertEquals(9, abcSize.size());
    }
}
